<%@ include file="css/header.jsp" %>
<title>RD Tracking</title>
<%
String userId;
String rdTracking;
String reRDRD;
String reJPMCRD;
if((String)session.getAttribute("userId")==null||((String)session.getAttribute("userId")).trim().length() == 0) userId = "null";
else userId = (String)session.getAttribute("userId");
if((String)session.getAttribute("rdTracking")==null||((String)session.getAttribute("rdTracking")).trim().length() == 0) rdTracking = "null";
else rdTracking = (String)session.getAttribute("rdTracking");
if((String)session.getAttribute("reRDRD")==null||((String)session.getAttribute("reRDRD")).trim().length() == 0) reRDRD = "null";
else reRDRD = (String)session.getAttribute("reRDRD");
if((String)session.getAttribute("reJPMCRD")==null||((String)session.getAttribute("reJPMCRD")).trim().length() == 0) reJPMCRD = "null";
else reJPMCRD = (String)session.getAttribute("reJPMCRD");
	if(!(userId.equals("null"))){
		if(rdTracking.equals("1")){
%>
<script type="text/javascript">
	var jqueryOption = {};
	jqueryOption.grdRowNum = 50;
	jqueryOption.grdRowList = [50, 100, 200];
	jqueryOption.grdJsonReader = {
	    root: "rows",
	    page: "page",
	    total: "total",
	    records: "records",
	    repeatitems: true, //if 'false' will chage json reader format to 'name' require
	    //cell: "cell",
	    id: "0" //id: "id"
	};
	var TrackViewerRD = new (function() {
        /**
         * Page Function
         */
        this.doError = function ()  {
            $.msgbox('Load Failed', {
                type : 'error'
            }, function(buttonPressed) {
            	//window.location.href = "index.html";
            });
        };

        this.bindgrdTransaction = function (ipage){
            var formObj = $("#formTrackViewerRD");
            var strUrl = formObj.serialize();
            
            $("#grdTransaction").jqGrid('setGridParam'
                    ,{url:"<%=request.getContextPath()%>/ViewServletRD/BindGrdTransaction"
                            +"?" + strUrl
                        ,page: ipage}).trigger("reloadGrid");
        };
    })();

$(document).ready(function() {
	$('#mnu li').hover(
	        function () {
	            //show its submenu
	            $('ul', this).slideDown(100);
	 
	        }, 
	        function () {
	            //hide its submenu
	            $('ul', this).slideUp(100);         
	        }
	    );
	
    	$("#btnSearch").click(function(){
    		TrackViewerRD.bindgrdTransaction(1);
            return false;
        });
    	
	var grdObj = $("#grdTransaction");
        grdObj.jqGrid({
        	datatype: 'json',
            mtype: 'POST',
            colNames:['Conversation ID','Status','Time','PAYLOAD Name','To JPMC','To RD',],
            colModel:[
                      {name:'conversationid', index:'conversationid',width:14, sortable:true,formatter:'showlink',formatoptions:{baseLinkUrl:'<%=request.getContextPath()%>/TrafficViewerServletRD'}},
                      {name:'status', index:'status',title:false, width:19, sortable:true},
                      {name:'time', align:'center',index:'time', width:19,sortable:true},
                      {name:'tcdattach', index:'tcdattach',width:32, sortable:false},           
	                  {name:'resend', align:'center',index:'resend', width:8,sortable:false},
    	              {name:'redownload',align:'center', index:'redownload', width:8,sortable:false}
            ],
            postData: {
            },
            rowNum: jqueryOption.grdRowNum, //50
            rowList: jqueryOption.grdRowList, //[50, 100, 200]
            autowidth: true, //Equal Container !Not change when resize window
            height: -1, //Auto height
            scrollOffset: 1, //Hide scroll bar
            pager: '#pagerTransaction',
            rownumbers: true,
            viewrecords: true,
            sortname: 'time',
            sortorder: "desc",
            cache: false,
            caption: 'Transaction Log RD',
            emptyrecords: 'No result',
            jsonReader : jqueryOption.grdJsonReader,
            onPaging: function(pgButton){ //pgButton : check which button click
            	TrackViewerRD.bindgrdTransaction($("#grdTransaction").getGridParam('page'));
            },
            onSortCol: function(index, iCol, sortorder){
            	TrackViewerRD.bindgrdTransaction($("#grdTransaction").getGridParam('page'));
            },
            loadError: function(xhr, status, error) {
            	//TrackViewer.doError();
            },
            loadComplete: function(data) {
                try {
					if(data.error != null){
	                	$.msgbox(data.error, {
	                        type : 'error'
	                    }, function(buttonPressed) {
	                    
	                    });
					}
				} catch (e) {
					
				}
            },
            gridComplete: function() {
                
            	var gridObj = $("#grdTransaction");
                var ids = gridObj.jqGrid('getDataIDs');
                var contentValue;
                for (var i = 0; i < ids.length; i++) {
                    var rowid = ids[i];
                    contentValue = gridObj.jqGrid('getRowData',rowid);
                    var resend = '<a href="javascript:void(0)" onClick="resend(\''+rowid+ '\'); return false">Resend</a>';
                    var redownload= '<a href="javascript:void(0)" onClick="redownload(\''+rowid+ '\'); return false">Resend</a>';
                    var notRe = '--';
                    if(contentValue.resend == 1)
                    	 gridObj.jqGrid('setRowData',rowid,{resend:resend});
                    else gridObj.jqGrid('setRowData',rowid,{resend:notRe});
                	if(contentValue.redownload == 1)
                   		gridObj.jqGrid('setRowData',rowid,{redownload:redownload});  
                	else gridObj.jqGrid('setRowData',rowid,{redownload:notRe});
            	}
                	
            }
        });
    });

function resend(converId){
	window.location.href = "ResendFileServlet?converId="+converId+"&type=reJPMCRD";
}


function redownload(converId){
	window.location.href = "ResendFileServlet?converId="+converId+"&type=reRDRD";
}
</script>

<body>
<div id="jp-main">
        <div class="jp-sheet">
            <div class="jp-sheet-tl"></div>
            <div class="jp-sheet-tr"></div>
            <div class="jp-sheet-bl"></div>
            <div class="jp-sheet-br"></div>
            <div class="jp-sheet-tc"></div>
            <div class="jp-sheet-bc"></div>
            <div class="jp-sheet-cl"></div>
            <div class="jp-sheet-cr"></div>
            <div class="jp-sheet-cc"></div>
            <div class="jp-sheet-body">
                <div class="jp-header">
                    <div class="jp-header-center">
                        <div class="jp-header-png"></div>
                        <div class="jp-header-jpeg"></div>
                    </div>
                        <div class="jp-header-fluid-object"></div>
                </div>
                <div class="jp-nav">
                	<div class="l"></div>
                	<div class="r"></div>
                	<ul class="jp-menu">
                		
                			<%if (session.getAttribute("tcdTracking").equals("1")){%>
					    	  <li>
					    	  	<a href="ViewServlet"><span class="l"></span><span class="r"></span><span class="t">TCD Tracking</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (session.getAttribute("rdTracking").equals("1")){%>
					    	  <li>
					    	  	<a href="ViewServletRD" class="active"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">RD Tracking</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (session.getAttribute("tcdBilling").equals("1")){%>
					    	  <li>
					    	  	<a href="TCDBillingServlet"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">TCD Billing</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (session.getAttribute("rdBilling").equals("1")){%>
					    	  <li>
					    	  	<a href="RDBilling"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">RD Billing</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (!(userId.equals("0"))){%>
					    	  <li>
					    	  	<a href="EditProfile.jsp"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">Edit profile</span></a>                		
                			  </li>
					      	<%} %>
                			
           		  		<li>
                			<a href="#"><span class="l"></span><span class="r"></span><span class="t">User Management</span></a>
							<ul>
								<%if (session.getAttribute("manageUsers").equals("1")){%>
						    		<li><a href="ManageAdminServlet">Manage users</a></li>
						      	<%} %>
						      	<%if (session.getAttribute("manageGroups").equals("1")){%>
					    			<li><a href="ManageGroupServlet">Manage groups</a></li>
					      		<%} %>
					      		<%if (session.getAttribute("userLog").equals("1")){%>
					    			<li><a href="UserLogServlet">User log</a></li>
					      		<%} %>
           					</ul>
               		  	</li>		
           		  	  	<li>
                			<a href="Logout"><span class="l"></span><span class="r"></span><span class="t">Logout</span></a>                		
                	  	</li>
               	  </ul>
                </div>
                <div class="jp-content-layout">
                  <div class="jp-post-body">
                     <h2 class="jp-postheader"> RD Tracking</h2>
                      <div class="jp-postcontent">
                      <script>
    						var date ;
    						function formatDate(d){
    							  var curr_date = d.getDate();
								  var curr_month = d.getMonth() + 1; //months are zero based
								  var curr_year = d.getFullYear();
								  var curr_hour = d.getHours();
								  var curr_minute = d.getMinutes();
								  var curr_second = d.getSeconds();
		
								  date = curr_year+"-"+curr_month+"-"+curr_date+" "+curr_hour+":"+curr_minute+":"+curr_second
        						}
							$(function() {
								 var d = new Date();
								 d.setDate(d.getDate() - 1);
								 formatDate(d);
								$("#fromTime").val(<%=request.getAttribute("fromTime")%>);
								$("#fromTime").datepicker({
									dateFormat: 'yy-mm-dd'
								});
							});
							$(function() {
								 var d = new Date();
								 formatDate(d);
								$("#toTime").val(<%=request.getAttribute("toTime")%>);
								$("#toTime").datepicker({
									dateFormat: 'yy-mm-dd'
								});
							});
						</script>
						<div id="TrackViewerRD">
                        <fieldset id="fsTrackViewerRD">
			            <legend class="pageTitleSearch"><h3>RD Search form</h3></legend>
			            <form id="formTrackViewerRD" method="POST" class="form" >
			                <fieldset>
			                    <ol>
			                    	<li class="">
			                            <div class="colTile">
			                              <label for="txtDate">Date</label>
			                            </div>
			                            <div class="colContent">
			                                 Start Date : <input type="text" name="fromTime" id="fromTime" value="" /> End Date : <input type="text" name="toTime" id="toTime" value="" /><br/>
			                            </div>
			                        </li>
			                        <li class="">
			                            <div class="colTile">
			                              <label for="txtAction">Customs type</label>
			                            </div>
			                            <div class="colContent">
			                                <select id="ddlCustomType" name="ddlCustomType" class="width-30">
				                                <option value="">-------ALL-------</option>
				                                <option value="RD2BANK">RD2BANK</option>
				                                <option value="BANK2RD">BANK2RD</option>
                            				</select>   
			                            </div>
			                        </li>
			                        <li class="">
			                            <div class="colTile">
			                              <label for="txtStatus">Status</label>
			                            </div>
			                            <div class="colContent">
			                               <select id="ddlStatus" name="ddlStatus" class="width-30">
				                                <option value="">-------ALL-------</option>
				                                <option value="<%=request.getAttribute("recvTcdStatus")%>">RECEIVE FILE FROM RD</option>
				                                <option value="<%=request.getAttribute("beginSendJpmcStatus")%>">BEGIN SEND FILE TO BANK</option>
				                                <option value="<%=request.getAttribute("finSendJpmcStatus")%>">FINISH SEND FILE TO BANK</option>
				                                <option value="<%=request.getAttribute("recvJpmcStatus")%>">RECEIVE FIlE FROM BANK</option>
				                                <option value="<%=request.getAttribute("sendTcdStatus")%>">BEGIN SEND FILE TO RD</option>
				                                <option value="<%=request.getAttribute("finSendTcdStatus")%>">FINISH SEND FILE TO RD</option>
                            				</select>   
			                            </div>
			                        </li>
			                        <li class="">
			                            <div class="colTile">
			                              <label for="txtConverId">Conversation ID</label>
			                            </div>
			                            <div class="colContent">
			                             <input type="text" name="conversationId" id="conversationId" value=""/>
			                            </div>
			                        </li>
			                        <li>
			                            <div  class="colTile">
			                                &nbsp;
			                            </div>
			                            <div class="colContent">
			                                <div id="btnCommand">
			                                   <button id="btnClear" type="reset" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"><span class="ui-button-icon-primary ui-icon ui-icon-refresh"></span><span class="ui-button-text">Clear</span></button>
			                                   <button id="btnSearch" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" ><span class="ui-button-icon-primary ui-icon ui-icon-search"></span><span class="ui-button-text">Search</span></button>
			                                </div>
			                            </div>
			                        </li>
			                    </ol>
			                </fieldset>
			            </form>
                            <div id="content-placeholder">
                                <div id="jqgrid">
                                    <table id="grdTransaction"></table>
                                    <div id="pagerTransaction"></div>
                                </div>
                            </div>
			        	</fieldset>       
			        	</div>              
			        	
                      </div>
                  </div>
                </div>
            </div>
        </div>
</div>
    
</body>	
<%
		}else{
%>
<script type="text/javascript">
    	window.location.href = "EditProfile";
</script>
<%
		}
	}else{
%>
<script type="text/javascript">
	window.location.href = "LoginServlet";
</script>
<%
	}
	
%>
</html>